package com.example.myapplication.presenter;


import android.app.Activity;
import android.app.Dialog;
import android.content.Context;

import com.example.myapplication.base.RxPresenter;
import com.example.myapplication.model.bean.DownListBean;
import com.example.myapplication.model.https.RetrofitDownloadManager;
import com.example.myapplication.model.https.RetrofitHelpers;
import com.example.myapplication.model.rx.RxSubscriber;
import com.example.myapplication.presenter.contract.DownloadContract;
import com.example.myapplication.ui.wight.LoadingDialog;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/*      *
 * Created by yin97 on 2017/4/4.
 */

public class DownloadPresenter extends RxPresenter<DownloadContract.View> implements DownloadContract.Presenter {

    Context mContext;
    RetrofitDownloadManager mRetrofitDownloadManager;
    public DownloadPresenter(Context context, RetrofitDownloadManager mRetrofitDownloadManager) {
        this.mContext=context;
        this.mRetrofitDownloadManager=mRetrofitDownloadManager;
    }

    @Override
    public void requestSplashData(int page, int type) {
        Dialog dialog= LoadingDialog.showDialogForLoading((Activity) mContext,"加载中...",false,false);
        listBeanObservable(page,type).subscribe(new RxSubscriber<DownListBean>(dialog) {
            @Override
            protected void _onNext(DownListBean downListBean) {
                mView.scouss(downListBean);
            }

            @Override
            protected void _onError(String message) {

            }
        });
    }

    private Observable<DownListBean> listBeanObservable(int page, int type) {
        return RetrofitHelpers.getInstance(5,false).getDownloadList(page,type).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    }

}
